package fr.cnam.ratpProject.client.activities.home;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.googlecode.mgwt.dom.client.event.tap.TapEvent;
import com.googlecode.mgwt.dom.client.event.tap.TapHandler;
import com.googlecode.mgwt.ui.client.widget.Button;

import fr.cnam.ratpProject.client.activities.home.HomeActivity.Action;
import fr.cnam.ratpProject.client.activities.home.HomeActivity.HomeView;
import fr.cnam.ratpProject.client.utils.RatpCommand;

public class HomeViewImpl extends Composite implements HomeView {

	private FlexTable main = new FlexTable();
	
	
	private RatpCommand<Action> actionCommand;
	
	
	private class MyTapHandler implements TapHandler
	{
		private Action action;

		public MyTapHandler(Action action)
		{
			this.action = action;
		}

		@Override
		public void onTap(TapEvent event) {
			if(actionCommand != null)
				actionCommand.execute(action);
		}
	}
	
	public HomeViewImpl()
	{
		initWidget(main);
		
		Button btnPlan = new Button("Plan des lignes");
		Button btnClass = new Button("Classements");
		Button btnItin = new Button("Recherche itinéraire");
		Button btnInfo = new Button("Infos trafic");
		Button btnRech = new Button("Recherche station");
		
		btnPlan.addTapHandler(new MyTapHandler(Action.PLAN));
		btnClass.addTapHandler(new MyTapHandler(Action.CLASSEMENT));
		btnItin.addTapHandler(new MyTapHandler(Action.ITINERAIRE));
		btnInfo.addTapHandler(new MyTapHandler(Action.INFOS));
		btnRech.addTapHandler(new MyTapHandler(Action.STATION));
		
		
		main.setWidget(0, 0, btnPlan);
		main.setWidget(0, 1, btnClass);
		main.setWidget(1, 0, btnItin);
		main.setWidget(1, 1, btnInfo);
		main.setWidget(2, 0, btnRech);
		main.setWidth("100%");
		main.getFlexCellFormatter().setColSpan(2, 0, 2);
		
		
		
	}


	@Override
	public void setActionCommand(RatpCommand<Action> command) {
		this.actionCommand = command;
	}

}
